<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function ajax_get(option){
            let xhr=new XMLHttpRequest()
            if(option.params){
                let str='?'
               for(let key in option.params){
                str+=`${key}=${option.params[key]}`
                str+='&'
               }
               str=str.slice(0,-1)
               xhr.open('get',option.url+str)
            }else{
                xhr.open('get',option.url)
            }
            
            xhr.onreadystatechange=()=>{
                if(xhr.readyState===4){
                    if(xhr.status===200){
                        option.success&&option.success(xhr.responseText)
                    }else{
                        option.error&&option.error()
                    }

                }
            }
            xhr.send()
        }
        ajax_get({
            url: 'http://localhost:8888/test/third',
            params: {name: '张三', age: 18},
            success(data){
                console.log(JSON.parse(data))
            }
        })
    </script>
</body>
</html>